//% color="#66CDAA" iconWidth=50 iconHeight=40
namespace DFRobot_I2C_GNSS {
    //% block="DFRobot_I2C_GNSS Init " blockType="command" 
  
    export function DFRobot_I2C_GNSSInit(parameter: any, block: any) {
  
      Generator.addImport("from DFRobot_GNSSAndRTC import DFRobot_GNSSAndRTC_I2C");
      Generator.addImport("import time");
  
      Generator.addCode("gnss_pt = DFRobot_GNSSAndRTC_I2C(0)");
  
      Generator.addCode(`while not gnss_pt.begin():
    print("No Deivces!")
    time.sleep(1)
gnss_pt.enable_32k()
gnss_pt.enable_power();
gnss_pt.set_gnss(gnss_pt.EGPS_BEIDOU_GLONASS)`);
  
    }
    //% block="enablePower[SET]" blockType="command"
    //% SET.shadow="dropdown"   SET.options="SET"
    export function DFRobot_I2C_GNSSablePower(parameter: any, block: any) {
      let set = parameter.SET.code;
      Generator.addCode([`gnss_pt.${set}able_Power()`, Generator.ORDER_UNARY_POSTFIX])
  
    }

//     //% block="set time [Y][M][D][H][MM][S] " blockType="command"
//     //% Y.shadow="number"   Y.defl="2024"
//     //% M.shadow="number"   M.defl="1"
//     //% D.shadow="number"   D.defl="1"
//     //% H.shadow="number"   H.defl="0"
//     //% MM.shadow="number"   MM.defl="0"
//     //% S.shadow="number"   S.defl="0"
//     export function DFRobot_I2C_GNSSSetTime(parameter: any, block: any) {
//       let Y = parameter.Y.code;
//       let M = parameter.M.code;
//       let D = parameter.D.code;
//       let H = parameter.H.code;
//       let MM = parameter.MM.code;
//       let S = parameter.S.code;
//       Generator.addCode(`gnss_pt.set_hour_system(gnss_pt.E24HOURS)
// gnss_pt.set_time(${Y},${M},${D},${H},${MM},${S})
// `)
  
//     }

    // //% block="calibRTC time  " blockType="command"
    // export function DFRobot_I2C_GNSScalibRTC(parameter: any, block: any) {
    //   Generator.addCode([`gnss_pt.calib_rtc()`, Generator.ORDER_UNARY_POSTFIX])
  
    // }
    // //% block="calibRTC time [SR] " blockType="command"
    // //% SR.shadow="range"   SR.params.min=1    SR.params.max=255    SR.defl=1
    // export function DFRobot_I2C_GNSScalibRTC1(parameter: any, block: any) {
    //   let SR = parameter.SR.code;
    //   Generator.addCode([`gnss_pt.set_hour_system(gnss_pt.E24HOURS)\ngnss_pt.calib_rtc_hour(${SR})`, Generator.ORDER_UNARY_POSTFIX])
  
  
    // }
    // //% block="calibStatus ? " blockType="boolean"
    // export function DFRobot_I2C_GNSScalibStatus(parameter: any, block: any) {
    //   Generator.addCode([`gnss_pt.calib_status() == gnss_pt.ECALIB_COMPLETE`, Generator.ORDER_UNARY_POSTFIX])
  
    // }

    //% block="Read the data once and save it and get the result" blockType="command"
    export function DFRobot_I2C_GNSSreaddata(parameter: any, block: any) {
  
      Generator.addCode(`utc_value = gnss_pt.get_utc()
date_value = gnss_pt.get_date()
lat_value = gnss_pt.get_lat()
lon_value = gnss_pt.get_lon()
high_value = gnss_pt.get_alt()
star_userd_value = gnss_pt.get_num_sat_used()
sog_value = gnss_pt.get_sog()
cog_value = gnss_pt.get_cog()
ymd = str(date_value.year)+str('/')+str(date_value.month)+str('/')+str(date_value.date)
hms = str(utc_value.hour)+str(':')+str(utc_value.minute)+str(':')+str(utc_value.second)`)
    }
  
  
    //% block="set time [DATE] " blockType="reporter"
    //% DATE.shadow="dropdown"   DATE.options="DATE"
    export function DFRobot_I2C_GNSSgetDate(parameter: any, block: any) {
      let rtcdate = parameter.DATE.code;
  
      Generator.addCode([`${rtcdate}`, Generator.ORDER_UNARY_POSTFIX])
  
    }
  
    //% block="Fetch [DATA] from result" blockType="reporter"
    //% DATA.shadow="dropdown"   DATA.options="DATA"
    export function DFRobot_I2C_GNSSgetData(parameter: any, block: any) {
      let data = parameter.DATA.code;
      Generator.addCode([`${data}`, Generator.ORDER_UNARY_POSTFIX]);
  
    }
  

  
  }